/**
 * 
 */
package cn.maszy.service.impl.customer;

import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.maszy.common.Pager;
import cn.maszy.common.SessionFactory;
import cn.maszy.dao.customer.B_T_Ufp_MaintainMapper;
import cn.maszy.model.customer.B_T_Ufp_Maintain;
import cn.maszy.model.customer.B_T_Ufp_MaintainExample;
import cn.maszy.model.customer.B_T_Ufp_MaintainExample.Criteria;
import cn.maszy.service.customer.B_T_Ufp_MaintainService;

@Service
public class B_T_Ufp_MaintainServiceImpl implements B_T_Ufp_MaintainService {
	@Autowired
	private B_T_Ufp_MaintainMapper B_T_Ufp_MaintainMapper;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.maszy.service.investment.B_T_Ufp_MaintainService#update(cn.maszy.model
	 * .investment.B_T_Ufp_Maintain,
	 * cn.maszy.model.investment.B_T_Ufp_MaintainExample)
	 */
	public int update(B_T_Ufp_Maintain B_T_Ufp_Maintain) {
		// TODO Auto-generated method stub
		if (B_T_Ufp_Maintain.getMaintainId() == null
				|| "".equals(B_T_Ufp_Maintain.getMaintainId())) {
			B_T_Ufp_Maintain.setMaintainId(UUID.randomUUID().toString());
			B_T_Ufp_Maintain.setIsDelete(0);
			B_T_Ufp_Maintain.setParenModouleName("SELLFOLLOW");
			B_T_Ufp_Maintain.setCreateTime(new Date());
			B_T_Ufp_Maintain.setCreateUser(SessionFactory
					.getSessionUserRealNam());
			return B_T_Ufp_MaintainMapper.insert(B_T_Ufp_Maintain);
		} else {
			B_T_Ufp_Maintain.setUpdateTime(new Date());
			B_T_Ufp_Maintain.setUpdateUser(SessionFactory
					.getSessionUserRealNam());
			return B_T_Ufp_MaintainMapper
					.updateByPrimaryKeySelective(B_T_Ufp_Maintain);
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.maszy.service.investment.B_T_Ufp_MaintainService#selectOne(java.lang
	 * .String)
	 */
	public B_T_Ufp_Maintain selectOne(String uuid) {
		// TODO Auto-generated method stub
		B_T_Ufp_Maintain record = B_T_Ufp_MaintainMapper
				.selectByPrimaryKey(uuid);
		return record;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.maszy.service.investment.B_T_Ufp_MaintainService#delete(java.lang.
	 * String)
	 */
	public int delete(String checkIds) {
		// TODO Auto-generated method stub
		B_T_Ufp_Maintain record = new B_T_Ufp_Maintain();
		for (String id : checkIds.split(", ")) {
			// 逻辑删除
			// 修改主表 isdelete
			if (!"on".equals(id)) {
				record = B_T_Ufp_MaintainMapper.selectByPrimaryKey(id);
				record.setIsDelete(1);
				B_T_Ufp_MaintainMapper.updateByPrimaryKey(record);
			}
		}
		return 1;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.maszy.service.investment.B_T_Ufp_MaintainService#count(cn.maszy.model
	 * .investment.B_T_Ufp_MaintainExample)
	 */
	public int count(B_T_Ufp_MaintainExample example,
			B_T_Ufp_MaintainMapper B_T_Ufp_MaintainMapper) {
		// TODO Auto-generated method stub
		return B_T_Ufp_MaintainMapper.countByExample(example);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * cn.maszy.service.investment.B_T_Ufp_MaintainService#selectList(cn.maszy
	 * .model.investment.B_T_Ufp_Maintain)
	 */
	public Pager<B_T_Ufp_Maintain> selectList(
			B_T_Ufp_Maintain B_T_Ufp_Maintain, Pager<B_T_Ufp_Maintain> pager) {
		// TODO Auto-generated method stub
		// 添加查询条件
		B_T_Ufp_MaintainExample example = new B_T_Ufp_MaintainExample();
		Criteria criteria = example.createCriteria();
		if (B_T_Ufp_Maintain != null) {
			if (B_T_Ufp_Maintain.getMaintainName() != null
					&& !"".equals(B_T_Ufp_Maintain.getMaintainName())) {
				criteria.andMaintainNameLike("%"+ B_T_Ufp_Maintain.getMaintainName() + "%");
			}
		}
		criteria.andParenModouleNameEqualTo("SELLFOLLOW");
		criteria.andIsDeleteEqualTo(0);
		example.or(criteria);
		int totalCount = new B_T_Ufp_MaintainServiceImpl().count(example,
				B_T_Ufp_MaintainMapper);
		pager.setTotalRecords(totalCount);
		example.setLimitStart(pager.getStartRecord());
		example.setLimitEnd(pager.getPageSize());
		example.setOrderByClause(pager.getOrderField() + " "
				+ pager.getOrderDirection());
		// 取得总的记录条数
		List<B_T_Ufp_Maintain> list = B_T_Ufp_MaintainMapper
				.selectByExample(example);
		pager.setPageRecords(list);
		return pager;
	}
	//用于查询生成下拉列表
	public List<B_T_Ufp_Maintain> selectListchange() {
		// TODO Auto-generated method stub
		// 添加查询条件
		B_T_Ufp_MaintainExample example = new B_T_Ufp_MaintainExample();
		Criteria criteria = example.createCriteria();
		criteria.andParenModouleNameEqualTo("SELLFOLLOW");
		criteria.andIsDeleteEqualTo(0);
		example.or(criteria);
		// 取得总的记录条数
		List<B_T_Ufp_Maintain> list = B_T_Ufp_MaintainMapper.selectByExample(example);
		return list;
	}
}
